<template lang="pug">
    skin(@up="up",@down="down",@yes="yes",@back="back",@duringUp="up",@duringDown="down")
        div(class="flex-column h2")
            div(class="flex-column-item")
            div(class="flex-column-item center")
                span(v-if="state=='ready'") 请输入密码:
                span(v-if="state=='fail'") 密码错误！！！
                span(v-if="state=='success'") 按ACT键恢复出厂
            div(class="flex-column-item center")
                control-password(@submit="submit",ref="cp",v-if="state=='ready'")
                span(@submit="submit",ref="cp",v-if="state=='fail'") 按任意键返回
                span(@submit="submit",ref="cp",v-if="state=='success'") 设置&nbsp;&nbsp;按ESC返回
            div(class="flex-column-item")
</template>

<script>
/** 恢复出厂值输入密码 */
export default {
    data(){
        return {
            state: 'ready',// 密码错误:fail 密码正确: success
         }
    },
    methods:{
        up(){
          if(this.state == 'ready') this.$refs.cp.up();
          if(this.state == 'fail') this.$router.push({path: 'index', query:{index: 3}});
        },
        down(){
          if(this.state == 'ready')  this.$refs.cp.down();
          if(this.state == 'fail') tthis.$router.push({path: 'index', query:{index: 3}});
        },
        yes(){
          if(this.state == 'ready')   this.$refs.cp.yes();
          else if(this.state == 'fail') this.$router.push({path: 'index', query:{index: 3}});
          else if(this.state == 'success') {
              // 恢复出场值跳转刷新
              const prefix = location.origin + location.pathname;
              location.href =prefix + '#/machine-setting/index?index=3';
          }
        },
        back(){
          if(this.state == 'ready') this.$refs.cp.back();
          else if(this.state == 'fail') this.$router.push({path: 'index', query:{index: 3}});
          else if(this.state == 'success') this.$router.push({path: 'index', query:{index: 3}});
        },
        submit(password){
            if(password == "1234"){
                this.state = 'success'
            }else{
                this.state = 'fail'
            }
        }
    }
}
</script>

<style>

</style>
